<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function newString (str){
            return newStr = str.split('').reverse().join('')
        }
        let data = 'String';
        let newData = newString(data)
        console.log(newData);
   

var foo ;
(function(){
    var foo = 1;
    
})()

alert(foo)


function foo() {
    var num = 10;
    return function () {
    var age= 20;
    console.log(++num);
    console.log(++age);
    }
}
var f = foo();
f(); //11 21
f(); //12 21

console.log(typeof[],typeof{});


  function promiseFn(options){
      return new Promise((reslove,reject)=>{
        if (condition) {
            reslove(data)
        }else{
            reject(data)
        }
      }).then(res=>{
          console.log(res);
      }).catch(err=>{
          console.log(err);
      })
  }


   function diffArr(arr){
     let newArr = [];
      for(let i in arr){
          if (newArr.indexOf(arr[i])==-1) {
              newArr.push(arr[i])
          }
      }
      return newArr
   }

   let arr = [1,2,3,4,4,5,5,6,6];

 let newArr = Array.from(new Set(arr))
   console.log(diffArr(arr));
   console.log(newArr);
// JSON.parse(JSON.stringify(obj));
// Object.assign()

function deepCopy(obj){
    let res = obj;
    if (typeof obj =='Object'&& obj !='null') {
        res = Object.prototype.toString.call(obj) =='[object Object]'?{}:[]
     for(let props in obj){
          res[prop]= deepCopy(obj[prop])
     }
    }
    return res

}

console.log(deepCopy(arr));





function deepCopy3(obj){
    let  res  = obj;
    if (typeof obj === 'object'&& obj != 'null') {
        res = Object.prototype.toString.call(obj) === '[object Object]'?{}:[]
      for(let props in obj){
          res[props] = deepCopy3(obj[props])
      }
    }
    return res
}
console.log(deepCopy3(arr));

//  arr.split('').reverse.join('')


  function getAjax(url){
      return new Promise((resolve,reject)=>{
          let xhr = new XMLHttpRequest();
          console.log(xhr);
          xhr.open('GET',url);
          xhr.send()
         xhr.onreadystatechange = function(){
            if (xhr.status == 200 && xhr.readyState == 4) {
                let result =  JSON.parse(xhr.response);
                // console.log(result);
                resolve(result)
          }else if( xhr.status != 200 && xhr.readyState != 4){
            reject()
              console.log(reject());
          }
         }

      }).then(res=>{
          console.log(res);
      }).catch(err=>{
          console.log(err);
      })
  }

  
  let url = 'https://api.apiopen.top/getJoke?page=1&count=2&type=video';
//    let data = ;
   console.log(getAjax(url));








    </script>
</body>
</html>